package vip.xiaozhao.paotui.intf.enums;


import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

public enum PaotuiTimeTypeEnum {

    All(0, "所有"),
    inHalf1H(1, "半小时内"),
    In2H(2, "2小时内"),
    In5H(3, "5小时内"),
    IN1D(4, "1天内"),
    Other(5, "大于1天");

    private int id;
    private String name;


    PaotuiTimeTypeEnum(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public static PaotuiTimeTypeEnum getById(int id) {
        for (PaotuiTimeTypeEnum type : PaotuiTimeTypeEnum.values()) {
            if (type.getId() == id)
                return type;
        }
        return null;
    }

    public static Date getDateByType(int id){
        if(id == inHalf1H.getId()){
            //时间计算 now()
            LocalDateTime now = LocalDateTime.now();
            LocalDateTime halfHourLater = now.plus(Duration.ofMinutes(30));
            //默认时区 转为Date
            Date date = Date.from(halfHourLater.atZone(ZoneId.systemDefault()).toInstant());
            return date;
        }
        if(id == In2H.getId()){
            LocalDateTime now = LocalDateTime.now();
            LocalDateTime halfHourLater = now.plus(Duration.ofHours(2));
            Date date = Date.from(halfHourLater.atZone(ZoneId.systemDefault()).toInstant());
            return date;
        }
        if(id == In5H.getId()){
            LocalDateTime now = LocalDateTime.now();
            LocalDateTime halfHourLater = now.plus(Duration.ofHours(5));
            Date date = Date.from(halfHourLater.atZone(ZoneId.systemDefault()).toInstant());
            return date;
        }
        if(id == IN1D.getId()){
            LocalDateTime now = LocalDateTime.now();
            LocalDateTime halfHourLater = now.plus(Duration.ofDays(1));
            Date date = Date.from(halfHourLater.atZone(ZoneId.systemDefault()).toInstant());
            return date;
        }
        if(id == Other.getId()){
            LocalDateTime now = LocalDateTime.now();
            LocalDateTime halfHourLater = now.plus(Duration.ofDays(1));
            Date date = Date.from(halfHourLater.atZone(ZoneId.systemDefault()).toInstant());
            return date;
        }
        return null;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    /**
     * Getter method for property <tt>name</tt>.
     *
     * @return property value of name
     */
    public String getName() {
        return name;
    }

    /**
     * Setter method for property <tt>name</tt>.
     *
     * @param name value to be assigned to property name
     */
    public void setName(String name) {
        this.name = name;
    }

    public static void main(String[] args) {
        System.out.println(getById(1).getName());
    }

}
